home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 January / maximum-cd-2000-01.iso / Dreamweaver2 / data1.cab / Program_Files / Configuration / Behaviors / Actions / Control Shockwave or Flash.js < prev    next >
Encoding:
JavaScript  |  1999-02-23  |  12.1 KB  |  342 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //****************** GLOBAL VARS ***************
  4.  
  5. function initGlobals() {
  6.   FLASHSTOP = "StopPlay";
  7.   DIRSTOP   = "Stop";  //default
  8.   CMDARRAY  = new Array("Play",DIRSTOP,"Rewind","GotoFrame");
  9.  
  10.   //use to check EMBEDs for Shockwave
  11.   FLASHSUFFIX  = new Array(".swf",".spl");
  12.   DIRSUFFIX    = new Array(".dir",".dcr");
  13.  
  14.   //use to check OBJECTs for Shockwave
  15.   FLASHCLASSID = "CLSID:D27CDB6E-AE6D-11CF-96B8-444553540000"; //must be all caps
  16.   DIRCLASSID   = "CLSID:166B1BCA-3F9C-11CF-8075-444553540000"; //must be all caps
  17. }
  18.  
  19. var FLASHSTOP;
  20. var DIRSTOP;
  21. var CMDARRAY;
  22. var FLASHSUFFIX;
  23. var DIRSUFFIX;
  24. var FLASHCLASSID;
  25. var DIRCLASSID;
  26.  
  27. //******************* BEHAVIOR FUNCTION **********************
  28.  
  29. //Causes a Shockwave object to play, stop, rewind, or go to a frame.
  30. //Accepts the following arguments:
  31. //  objStrNS - Javascript embed ref for Netscape, empty for OBJECTs (ex: document.myShock)
  32. //  objStrIE - JScript object or embed reference for Internet Explorer (ex: document.all['myShock'])
  33. //  cmdName  - method to invoke: Play(), Rewind(), GotoFrame(frameNum), 
  34. //             StopPlay() for a Flash Movie, Stop() for Director
  35. //  frameNum - (optional) frame number, only used with GotoFrame method
  36. //
  37. //Tests for browser, and uses the first object string for NS, the second for IE
  38. //Fixes the obj reference if its in a layer and layers aren't supported (older browsers).
  39. //Then tests to see if the browser doesn't support the object, which
  40. //does the job of checking for the correct plugin or ActiveX object.
  41. //Evals the concatenated pieces to call the method, for ex: document.myShock.Play()
  42.  
  43. function MM_controlShockwave(objStrNS,objStrIE,cmdName,frameNum) { //v2.0
  44.   var objStr = (navigator.appName=='Netscape')?objStrNS:objStrIE;
  45.   if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
  46.       (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
  47.     objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
  48.   if (eval(objStr) != null)
  49.     eval(objStr+'.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
  50. }
  51.  
  52.  
  53. //******************* API **********************
  54.  
  55.  
  56. //Checks for the existence of Shockwave movie.
  57. //If none exist, returns false so this Action is grayed out.
  58.  
  59. function canAcceptBehavior(){
  60.   if (!FLASHSUFFIX) initGlobals();
  61.   var i,j,theTag,swSrc,classId;
  62.   var tagArray = new Array;
  63.   var refArray = new Array;
  64.  
  65.   //Find all EMBED calls that contain Shockwave objects in SRC
  66.   tagArray = getAllObjectTags("embed");
  67.   refArray = getAllObjectRefs("NS 4.0","embed");
  68.   for (i in tagArray) {  //with each EMBED tag
  69.     theTag = tagArray[i];
  70.     swSrc = unescQuotes(getParam(theTag,"src"));  //get the SRC value
  71.     for (j=0; j<FLASHSUFFIX.length; j++) if (swSrc.indexOf(FLASHSUFFIX[j])>0) return true;
  72.     for (j=0; j<DIRSUFFIX.length;   j++) if (swSrc.indexOf(DIRSUFFIX[j])>0) return true;
  73.   }
  74.  
  75.   //Find all OBJECT calls that contain Shockwave objects in ClassID
  76.   //Add each unique name to the menu
  77.   tagArray = getAllObjectTags("object");
  78.   refArray = getAllObjectRefs("NS 4.0","object");
  79.   for (i in tagArray) {
  80.     theTag = tagArray[i];
  81.     classId = unescQuotes(getParam(theTag,"classid"));
  82.     if (classId) {
  83.       if (classId.toUpperCase().indexOf(FLASHCLASSID) == 0) return true;
  84.       if (classId.toUpperCase().indexOf(DIRCLASSID)   == 0) return true;
  85.     }
  86.   }
  87.   return false;  //if none of the tests above returned "true"
  88. }
  89.  
  90.  
  91.  
  92. //Returns a Javascript function to be inserted in HTML head with script tags.
  93.  
  94. function behaviorFunction() {
  95.   return "MM_controlShockwave";
  96. }
  97.  
  98.  
  99.  
  100. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  101. //Calls escQuotes to find embedded quotes and precede them with \
  102.  
  103. function applyBehavior(uniqueName) {
  104.   var menuIndex,swObjNS,swObjIE,theRadio,i;
  105.   var cmdName="";
  106.   var theFrame="";
  107.  
  108.   //get shockwaveObject ID
  109.   menuIndex = document.theForm.menu.selectedIndex;
  110.   swObjNS = document.MM_NS_REFS[menuIndex];
  111.   swObjIE = document.MM_IE_REFS[menuIndex];
  112.   if (swObjNS.indexOf(REF_CANNOT)==0) {
  113.     swObjNS = "";
  114.     alert(MSG_NoNSRef)
  115.   }
  116.   if (swObjIE.indexOf(REF_CANNOT)==0) {
  117.     swObjIE = "";
  118.     alert(MSG_NoIERef);
  119.   }
  120.  
  121.   //get selected command from radio buttons
  122.   for (i=0; i<document.theForm.theCmd.length; i++) {
  123.     theRadio = document.theForm.theCmd[i];
  124.     if (theRadio.checked) {
  125.       cmdName = CMDARRAY[i];
  126.       if (cmdName == "GotoFrame") {  //get frame if GotoFrame
  127.         theFrame = document.theForm.frameNum.value;
  128.         if (theFrame != ''+parseInt(theFrame))
  129.           return MSG_InvalidFrameNum;
  130.         else if (parseInt(theFrame) < 0)
  131.           return MSG_NegFrameNum;
  132.       }
  133.       else if (cmdName == DIRSTOP) {  //Ensure it's correct stop cmd for Director/Flash
  134.         cmdName = (document.MM_shockwaveTypelist[menuIndex] == "FLASH")? FLASHSTOP : DIRSTOP;
  135.       }
  136.       break;
  137.     }
  138.   }
  139.  
  140.   if (swObjNS.indexOf(REF_UNNAMED) == 0)  //if unnamed reference
  141.     return MSG_UnnamedObj;
  142.     
  143.   enableFlashScripting( swObjNS );    
  144.     
  145.   if (cmdName) {
  146.     return "MM_controlShockwave('"+escQuotes(swObjNS)+"','"+escQuotes(swObjIE)+"','"+cmdName+((theFrame)?"','"+theFrame:"")+"')";
  147.   } else {
  148.     return MSG_NoSelection;
  149.   }
  150. }
  151.  
  152.  
  153. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  154. //call arguments. This information is used by DW to fixup behavior args when the
  155. //document is moved or changed.
  156. //
  157. //It is passed an actual function call string generated by applyBehavior(), which
  158. //may have a variable list of arguments, and this should return a matching mask.
  159. //
  160. //The return values are:
  161. //  URL     : argument could be a file path, which DW will update during Save As...
  162. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  163. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  164. //  other...: argument is ignored
  165.  
  166. function identifyBehaviorArguments(fnCallStr) {
  167.   var argArray;
  168.  
  169.   argArray = extractArgs(fnCallStr);
  170.   if (argArray.length == 4) {
  171.     return "NS4.0ref,IE4.0ref,other";
  172.   } else if (argArray.length == 5) {
  173.     return "NS4.0ref,IE4.0ref,other,other";
  174.   } else {
  175.     return "";
  176.   }
  177. }
  178.  
  179.  
  180.  
  181. //Passed the function call above, takes prior arguments and reloads the UI.
  182. //Removes any escape characters "\"
  183.  
  184. function inspectBehavior(argStr){
  185.   var swName,menuLength,i;
  186.   var argArray = new Array;
  187.   var found = false;
  188.  
  189.   argArray = extractArgs(argStr); //get args
  190.   if (argArray.length > 3) {  //should be 4 or 5 args (0 and 2 ignored)
  191.  
  192.     //select shockwaveId
  193.     swName = unescQuotes(argArray[1]);
  194.     menuLength = document.MM_NS_REFS.length;
  195.     for (i=0; i<menuLength; i++) { //search menu for matching shockwave name
  196.       if (document.MM_NS_REFS[i] == swName) { //if found
  197.         document.theForm.menu.selectedIndex = i;  //make it selected
  198.         found = true;
  199.         break;
  200.       }
  201.     }
  202.     if (!found) alert(errMsg(MSG_ShockwaveNotFound,swName));
  203.  
  204.     //select appropriate radio button
  205.     cmdName = argArray[3];
  206.     if (cmdName == FLASHSTOP) cmdName = DIRSTOP;
  207.     for (i=0; i<document.theForm.theCmd.length; i++)
  208.       document.theForm.theCmd[i].checked = (cmdName == CMDARRAY[i]);
  209.  
  210.     //stuff frame num if there
  211.     if (argArray.length > 4) {
  212.       document.theForm.frameNum.value = argArray[4];
  213.     }
  214.   }
  215. }
  216.  
  217.  
  218.  
  219. //***************** LOCAL FUNCTIONS  ******************
  220.  
  221.  
  222. //Searches for all Shockwave EMBEDs and OBJECTs on the page,
  223. //eliminating duplicates, and adding them to the menu.
  224.  
  225. function initializeUI(){
  226.   initGlobals();
  227.   var i,j,k,theTag,swSrc,swName,classId,notInMenu;
  228.   var tagArray = new Array;
  229.   var NSrefArray = new Array;
  230.   var IErefArray = new Array;
  231.   var paramArray = new Array;
  232.   var mIndex=0;
  233.   var isFlash, isDir;
  234.   var shockwaveTypelist = new Array;
  235.   var IErefs = new Array;
  236.   var NSrefs = new Array;
  237.   var niceNameArray = new Array;
  238.  
  239.   //Find all EMBED calls that contain ShockWave objects in SRC
  240.   //Add each unique name to the menu list
  241.   tagArray = getAllObjectTags("embed"); //get the tags to search
  242.   NSrefArray = getAllObjectRefs("NS 4.0","embed"); //get parallel EMBED obj refs
  243.   IErefArray = getAllObjectRefs("IE 4.0","embed");
  244.   for (i in tagArray) {  //with each EMBED tag
  245.     theTag = tagArray[i];
  246.     isFlash = false;  isDir = false;  //search for Flash or Director suffixes
  247.     swSrc = unescQuotes(getParam(theTag,"src"));  //get the SRC value
  248.     if (swSrc) {
  249.       for (j=0; j<FLASHSUFFIX.length; j++) if (swSrc.indexOf(FLASHSUFFIX[j])>-1) isFlash=true;
  250.       for (j=0; j<DIRSUFFIX.length;   j++) if (swSrc.indexOf(DIRSUFFIX[j])  >-1) isDir  =true;
  251.       if (isFlash || isDir) {  //if found Flash or Director file suffix
  252.         swName = IErefArray[i];
  253.         if (swName.indexOf(REF_CANNOT)==0) swName=NSrefArray[i]; //if invalid IE ref, use NS ref
  254.         if (swName) {
  255.           IErefs[mIndex] = IErefArray[i];   //store IE ref into parallel array
  256.           NSrefs[mIndex] = NSrefArray[i];   //store NS ref into parallel array
  257.           shockwaveTypelist[mIndex] = (isFlash)?"FLASH":"DIR";
  258.           niceNameArray[mIndex++] = swName;
  259.         }
  260.       }
  261.     }
  262.   }
  263.  
  264.   //Find all OBJECT calls that contain ShockWave classId
  265.   //Add each unique name to the menu
  266.   tagArray = getAllObjectTags("object");
  267.   NSrefArray = getAllObjectRefs("NS 4.0","object");
  268.   IErefArray = getAllObjectRefs("IE 4.0","object");
  269.   for (i in tagArray) {
  270.     theTag = tagArray[i];
  271.     isFlash = false;  isDir = false;  //search for Flash or Director suffixes
  272.     classId = unescQuotes(getParam(theTag,"classid"));
  273.     if (classId) {
  274.       if (classId.toUpperCase().indexOf(FLASHCLASSID) == 0) isFlash = true;
  275.       if (classId.toUpperCase().indexOf(DIRCLASSID)   == 0) isDir   = true;
  276.       if (isFlash || isDir) {
  277.         swName = IErefArray[i];
  278.         if (swName.indexOf(REF_CANNOT)==0) swName=NSrefArray[i]; //if invalid IE ref, use NS ref
  279.         if (swName) {
  280.           notInMenu = true;
  281.           for (k in niceNameArray) { //check if already in menu list
  282.             if (swName == niceNameArray[k]) { //if already in menu list
  283.               notInMenu=false;        //set flag
  284.               break;
  285.             }
  286.           }
  287.           if (notInMenu) {
  288.             IErefs[mIndex] = IErefArray[i];   //store IE ref into parallel array
  289.             NSrefs[mIndex] = NSrefArray[i];   //store NS ref into parallel array
  290.             shockwaveTypelist[mIndex] = (isFlash)?"FLASH":"DIR";
  291.             niceNameArray[mIndex++] = swName;
  292.           }
  293.         }
  294.       }
  295.     }
  296.   }
  297.   niceNameArray = niceNames(niceNameArray,TYPE_Shockwave); //convert list to nice names
  298.   for (i=0; i<niceNameArray.length; i++) { //write to SELECT
  299.     document.theForm.menu.options[i]=new Option(niceNameArray[i]); //load menu
  300.   }
  301.  
  302.   document.MM_IE_REFS = IErefs; //store parallel IE refs
  303.   document.MM_NS_REFS = NSrefs; //store parallel NS refs
  304.   document.MM_shockwaveTypelist = shockwaveTypelist;  //store types of each flash item
  305.   document.theForm.menu.selectedIndex = 0;
  306. }
  307.  
  308. // enableFlashScripting()
  309. //
  310. // As of Flash 3, the swliveconnect attribute must be enabled
  311. // on the Flash object in order to use it's scripting interface
  312. // in Netscape.  The option tells Netscape to preload Live 
  313. // Connect and the appropriate underlying Java classes.
  314. //
  315. function enableFlashScripting( nsObjRef )
  316. {
  317.    var userDoc = dreamweaver.getDocumentDOM( "document" );
  318.    var tagArr  = userDoc.getElementsByTagName( "embed" );
  319.    
  320.    tagArr = tagArr.concat( userDoc.getElementsByTagName( "object" ) );
  321.    
  322.    for( var i = 0; i < tagArr.length; i++ )
  323.    {
  324.       if ( nsObjRef == dreamweaver.getElementRef( "NS 4.0", tagArr[i] ) )
  325.       {
  326.          tagArr[i].setAttribute( "swliveconnect", true );
  327.          return;
  328.       }
  329.    }
  330. }
  331.  
  332.  
  333. //**************** GENERIC FUNCTIONS ****************
  334.  
  335. //function extractArgs(upStr){
  336. //function getParam(tagStr,param){
  337. //function escQuotes(theStr){
  338. //function unescQuotes(theStr){
  339. //function niceNames(objRefArray,objTypeStr) {
  340. //function nameReduce (objName) {
  341. //function errMsg() {
  342.